<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!--返回错误信息-->
<?php echo validation_errors(); ?>
<!DOCTYPE html>
<html lang="en">

<head>
    <?php
    $title = [
        'title' => '采购进货单',
    ];
    $this->load->view('/admin/common/header', $title);
    ?>
</head>

<body data-type="widgets">
<script src="/assets/js/theme.js"></script>
<div class="am-g tpl-g">

<!--    头部   侧边菜单-->
    <?php $this->load->view('/admin/common/bodyLeft'); ?>

    <!-- 内容区域 -->
    <div class="tpl-content-wrapper">
        <div class="row-content am-cf">
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <form action="/admin/supplier/remove" id="form_admin" method="post">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf">
                            <div class="widget-title  am-cf">采购项目单</div>
                            <ol class="am-breadcrumb am-breadcrumb-slash">
                                <li><a href="/admin/procurement/index?page=1">采购管理</a></li>
                                <li class="am-active">采购进货单</li>
                            </ol>
                        </div>
                            <div class="widget-body  am-fr">
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                                    <div class="am-form-group">
                                        <div class="am-btn-toolbar">
                                            <div class="am-g">
                                                <div class="am-u-sm-6">
                                                    <button type="button" class="am-btn am-btn-default am-margin-right" id="my-start">开始日期</button><span id="my-startDate">2014-12-20</span>
                                                </div>
                                                <div class="am-u-sm-6">
                                                    <button type="button" class="am-btn am-btn-default am-margin-right" id="my-end">结束日期</button><span id="my-endDate">2014-12-25</span>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                                    <div class="am-form-group tpl-table-list-select">
                                        <select data-am-selected="{btnSize: 'sm'}">
                                            <option value="option1">请选择审核状态</option>
                                            <option value="option2">全部状态</option>
                                            <option value="option3">待提交</option>
                                            <option value="option3">待验证生产</option>
                                            <option value="option3">待验收物料</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                                    <div class="am-form-group tpl-table-list-select">
                                        <select data-am-selected="{btnSize: 'sm'}">
                                            <option value="option1">供应商</option>
                                            <option value="option2">全部供应商</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                                    <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
    <!--                                    <form action="/admin/user/search" method="get">-->
                                        <input type="text" class="am-form-field" name="search" id="search">
                                        <span class="am-input-group-btn">
                                            <a href="javascript:void()" onclick="search123()" class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search">
                                                搜索
                                            </a>
              </span>
    <!--                                    </form>-->
                                    </div>
                                </div>
                                <div class="am-u-sm-12">
                                    <div class="am-form-group">
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <a href="javascript:void();" onclick="dai()" class="am-btn am-btn-default am-btn-success"><span
                                                            class="am-icon-plus"></span> 未完成进货单
                                                </a>
                                                <a href="javascript:void();" onclick="yi()" class="am-btn am-btn-default am-btn-danger"><span
                                                            class="am-icon-trash-o"></span> 已完成进货单
                                                </a>
                                                <a href="/admin/supplier/daochu" class="am-btn am-btn-default am-btn-danger"><span
                                                            class="am-icon-trash-o"></span> 导出
                                                </a>
                                                <a href="/admin/procurement/purchaseOrderAddView" class="am-btn am-btn-default am-btn-danger"><span
                                                            class="am-icon-trash-o"></span> 新增
                                                </a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="am-u-sm-12">
                                    <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black "
                                           id="example-r">
                                        <thead>
                                        <tr>
                                            <th>序号</th>
                                            <th>单据时间</th>
                                            <th>进货单编号</th>
                                            <th>关联需求单号</th>
                                            <th>进货单名称</th>
                                            <th>供应商</th>
                                            <th>所属项目</th>
<!--                                            <th>种类/数量</th>-->
<!--                                            <th>进货金额</th>-->
                                            <th>状态</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <?php
                                        foreach ($list as $v) {
                                             echo '    <td>'.$v['id'].'</td>
                                                    <td>'.date('Y-m-d',$v['createTime']).'</td>
                                                 <td>'.$v['purchaseCode'].'</td>
                                                 <td>'.$v['needCode'].'</td>
                                                 <td>'.$v['name'].'</td>
                                               <td>'.$v['supplier'].'</td>
                                               <td>'.$v['source'].'</td>';
//                                               <td>'.$v['attribute'].'</td>
//                                               <td>'.$v['amount'].'</td>

                                             switch ($v['status']){
                                                 case 0:
                                                     echo '<td>待提交</td>
                                                            <td>
                                                            <div class="tpl-table-black-operation">
                                                             <a href="/admin/procurement/purchaseEditView?id='.$v['id'].'">
                                                                    <i class="am-icon-pencil"></i> 编辑
                                                                </a>
                                                             <a href="/admin/procurement/remove?id='.$v['id'].'" class="tpl-table-black-operation-del">
                                                                <i class="am-icon-trash"></i> 删除
                                                            </a>
                                                            </div>
                                                            </tr>';
                                                     break;
                                                 case 1:
                                                     echo '<td>待财务确认付款</td>
                                                            <td>
                                                            <div class="tpl-table-black-operation">
                                                           
                                                            </tr>';
                                                     break;
                                                 case 2:
                                                     echo '<td>待验收生产</td>
                                                            <td>
                                                            <div class="tpl-table-black-operation">
                                                             <a href="/admin/procurement/purchaseEditView?id='.$v['id'].'&status='.$v['status'].'">
                                                                    <i class="am-icon-pencil"></i> 去处理
                                                                </a>
                                                            </div>
                                                            </tr>';
                                                     break;
                                                 case 3:
                                                     echo '<td>待验收物料</td>
                                                            <td>
                                                            <div class="tpl-table-black-operation">
                                                             <a href="/admin/procurement/purchaseEditView?id='.$v['id'].'&status='.$v['status'].'">
                                                                    <i class="am-icon-pencil"></i> 去处理
                                                                </a>
                                                            </div>
                                                            </tr>';
                                                     break;
                                                 case 4:
                                                     echo '<td>待付质保金</td>
                                                            <td>
                                                            <div class="tpl-table-black-operation">
                                                             <a href="/admin/procurement/purchaseEditView?id='.$v['id'].'&status='.$v['status'].'">
                                                                    <i class="am-icon-pencil"></i> 去处理
                                                                </a>
                                                            </div>
                                                            </tr>';
                                                     break;
                                                 case 5:
                                                     echo '<td>已完成</td>
                                                            <td>
                                                            <div class="tpl-table-black-operation">
                                                             <a href="/admin/procurement/editView?id='.$v['id'].'&status='.$v['status'].'">
                                                                    <i class="am-icon-pencil"></i> 去处理
                                                                </a>
                                                            </div>
                                                            </tr>';
                                                     break;
                                             }
                                        }
                                        ?>
                                        </tbody>
                                    </table>
                                </div>
                                <div class="am-u-lg-12 am-cf">
                                    <div class="am-fr">
                                        <ul class="am-pagination tpl-pagination" id="paging">
    <!--                                        <li class="am-active"><a href="#">1</a></li>-->
                                            <?php
                                            //$page_num = 4; //每页显示多少条
                                            //$totalNum;  //总页数
                                            $num = ceil($totalNum/$pageNum);
                                            @$search = $_GET['search'];
                                            @$page = $_GET['page'] ? $_GET['page'] : 1;

                                            for ($i = 1; $i <= $num; $i++) {
                                                if($search){
                                                    if($page == $i){
                                                        echo "<li class='am-active'><a href=?page=".$i."&search=$search>$i</a></li>";
                                                    }else{
                                                        echo "<li><a href=?page=".$i."&search=$search>$i</a></li>";
                                                    }
                                                }else{
                                                    if($page == $i){
                                                        echo "<li class='am-active'><a href=?page=".$i.">$i</a></li>";
                                                    }else{
                                                        echo "<li><a href=?page=".$i.">$i</a></li>";
                                                    }
                                                }
                                            }
                                            ?>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                    </div>
                    </form>

                </div>
            </div>
        </div>
    </div>
</div>
</div>
<script>
    function search123() {
        var v = document.getElementById('search').value;
        window.location.href='?page=1'+'&search='+v
    }
    function GetQueryString(name)
    {
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }
    function dai() {
        var search = GetQueryString('search');
        console.log(search);
        if(search == null){
            window.location.href='?page=1'+'&status=w'
        }else{
            window.location.href='?page=1'+'&search='+search+'&status=w'
        }
    }
    function yi() {
        var search = GetQueryString('search');
        if(search == null){
            window.location.href='?page=1'+'&status=y'
        }else{
            window.location.href='?page=1'+'&search='+search+'&status=y'

        }
    }
</script>
<script>
    $(function() {
        var startDate = new Date(2014, 11, 20);
        var endDate = new Date(2014, 11, 25);
        var $alert = $('#my-alert');
        $('#my-start').datepicker().
        on('changeDate.datepicker.amui', function(event) {
            if (event.date.valueOf() > endDate.valueOf()) {
                $alert.find('p').text('开始日期应小于结束日期！').end().show();
            } else {
                $alert.hide();
                startDate = new Date(event.date);
                $('#my-startDate').text($('#my-start').data('date'));
            }
            $(this).datepicker('close');
        });

        $('#my-end').datepicker().
        on('changeDate.datepicker.amui', function(event) {
            if (event.date.valueOf() < startDate.valueOf()) {
                $alert.find('p').text('结束日期应大于开始日期！').end().show();
            } else {
                $alert.hide();
                endDate = new Date(event.date);
                $('#my-endDate').text($('#my-end').data('date'));
            }
            $(this).datepicker('close');
        });
    });
</script>
<script>
    //todo 第一次选中可以,第二次不行
    /* 全选 */
    $('.checkall').click(function(){
        var _self = this;
        $('.checkitem').each(function(){
            if (!this.disabled)
            {
                $(this).attr('checked', _self.checked);
            }
        });
        $('.checkall').attr('checked', this.checked);
    });

</script>
<script src="/assets/js/amazeui.min.js"></script>
<script src="/assets/js/amazeui.datatables.min.js"></script>
<script src="/assets/js/dataTables.responsive.min.js"></script>
<script src="/assets/js/app.js"></script>

</body>

</html>